package com.maya.medicalwastes;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import java.util.List;

import butterknife.ButterKnife;

/**
 * @description 登录界面的机构列表的适配器
 * @user gzl
 * @date 2017/7/31
 * @time 13:22
 */

public class AuthOrgAdapter extends ArrayAdapter<String> {

    private int layout = -1;

    public AuthOrgAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<String> objects) {
        super(context, resource, objects);
    }

    public AuthOrgAdapter(@NonNull Context context, @LayoutRes int resource, @LayoutRes int layout, @NonNull List<String> objects) {
        super(context, resource, objects);
        this.layout = layout;
    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            if (layout == -1) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_auth_org, parent, false);
            } else {
                convertView = LayoutInflater.from(getContext()).inflate(layout, parent, false);
            }
            holder = new ViewHolder(convertView);
            holder.content = (TextView) convertView.findViewById(R.id.content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.content.setText(getItem(position));
        return convertView;
    }

    static class ViewHolder {
        TextView content;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
